package main

import (
	"iris-starter/bootstrap"
	"iris-starter/config"
	"iris-starter/datasource"
	"iris-starter/router"

	"github.com/iris-contrib/swagger/v12/swaggerFiles"

	"github.com/iris-contrib/swagger/v12"

	"github.com/spf13/pflag"
)

var confPath = pflag.StringP("config", "c", "", "config file path...")

func newApp(c *config.Config) *bootstrap.Bootstrapper {
	app := bootstrap.New(c)
	app.Bootstrap()
	return app
}

// @title Swagger Example API
// @version 1.0
// @description This is a sample server Petstore server.
// @termsOfService http://swagger.io/terms/

// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @host localhost:8082
// @BasePath /v1
func main() {
	pflag.Parse()

	_ = config.InitConfig(*confPath)
	_ = datasource.InitMysql(config.Conf)
	datasource.InitRedis(config.Conf)
	app := newApp(config.Conf)

	swagUI := swagger.WrapHandler(swaggerFiles.Handler, swagger.URL("http://localhost:8082/swagger/doc.json"))
	app.Get("/swagger/{any:path}", swagUI)

	//app.Configure(configurator.ConfigureLogger, router.ConfigureRouter)
	app.Configure(router.ConfigureRouter, router.ConfigureWebRouter)

	app.Listen()
}
